import { userRequest } from "./request";

//用户登录
export function login(user, pass) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/user/logging",
    data: {
      username: user,
      password: pass,
      loginTime: Date.now(),
    },
    xhrFields: { withCredentials: true },
  });
}

//退出登录
export function exitLogin(user) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/user/outLogin",
    data: {
      username: user,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户注册
export function register(user, pass) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/user/register",
    data: {
      username: user,
      password: pass,
    },
    xhrFields: { withCredentials: true },
  });
}

//保存用户信息
export function saveUserInfo(username, nickname, introduce, sex, birthday) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/user/saveUserInfo",
    data: {
      username: username,
      nickname: nickname,
      introduce: introduce,
      sex: sex,
      birthday: birthday,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户信息
export function getUserInfo(username) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/user/getUserInfo",
    data: {
      username: username,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户对指定歌手关注信息
export function getUserFollowSonger(username, songerId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/userFollowSonger",
    data: {
      username: username,
      followSongerId: songerId,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户关注歌手
export function followSonger(username, songerId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/followSonger",
    data: {
      username: username,
      followSongerId: songerId,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户对指定用户关注信息
export function getUserFollowUser(username, userId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/userFollowUser",
    data: {
      username: username,
      followUserId: userId,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户关注用户
export function followUser(username, userId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/followUser",
    data: {
      username: username,
      followUserId: userId,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户对指定专辑收藏信息
export function getUserCollectAlbum(username, albumId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/getUserCollectAlbum",
    data: {
      username: username,
      collectAlbumId: albumId,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户收藏专辑
export function collectAlbum(username, albumId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/collectAlbum",
    data: {
      username: username,
      collectAlbumId: albumId,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户对指定歌单收藏信息
export function getUserCollectSongList(username, songListId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/userCollectSongList",
    data: {
      username: username,
      collectSongListId: songListId,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户收藏歌单
export function collectSongList(username, songListId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/collectSongList",
    data: {
      username: username,
      collectSongListId: songListId,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户对指定MV收藏信息
export function getUserCollectMV(username, MVId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/userCollectSongList",
    data: {
      username: username,
      collectMVId: MVId,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户收藏MV
export function collectMV(username, MVId) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/collectMV",
    data: {
      username: username,
      collectMVId: MVId,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取用户点赞信息
export function getUserLiked(username, likedId, likedType) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/userLiked",
    data: {
      username: username,
      likedId: likedId,
      likedType: likedType,
    },
    xhrFields: { withCredentials: true },
  });
}

//用户点赞
export function liked(username, likedId, likedType) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/liked",
    data: {
      username,
      likedId,
      likedType,
    },
    xhrFields: { withCredentials: true },
  });
}

//评论
export function comment(objectId, userId, userImgName, userImgPath, avatarUrl, nickname, content, commentType) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/comment",
    data: {
      objectId,
      userId,
      userImgName,
      userImgPath,
      avatarUrl,
      nickname,
      time: Date.now(),
      content,
      commentType,
    },
    xhrFields: { withCredentials: true },
  });
}

//获取指定作品评论
export function getComment(objectId, userId, commentType) {
  return userRequest({
    method: "POST",
    url: "http://localhost:8081/interactive/getComment",
    data: {
      objectId,
      userId,
      commentType,
    },
    xhrFields: { withCredentials: true },
  });
}
